package com.wyg.state;

/**
 * @description:
 * @author: WYG
 * @time: 2021/4/7 9:44
 */

public class WinnerState implements State{
    GumballMachine gumballMachine;
    public WinnerState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }
    @Override
    public void insertQuarter() {
        System.out.println("您已投币，无须重复进行");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("您已转动曲柄，无法退钱啦");
    }

    @Override
    public void turnCrank() {
        System.out.println("不能两次转动曲柄");
    }

    @Override
    public void dispense() {
        System.out.println("恭喜您中奖了，您将会获得两个糖果");
        gumballMachine.releaseBall();
        if (gumballMachine.getCount() == 0) {
            gumballMachine.setState(gumballMachine.getSoldOutState());
        } else {
            gumballMachine.releaseBall();
            if (gumballMachine.getCount() > 0) {
                gumballMachine.setState(gumballMachine.getNoQuarterState());
            } else {
                System.out.println("糖果已售罄");
                gumballMachine.setState(gumballMachine.getSoldOutState());
            }
        }
    }
}
